package com.sky.controller.garbage;

import com.sky.dto.EnvirinmentalKnowledgeSaveDto;
import com.sky.dto.EnvironmentalKnowledePageDto;
import com.sky.service.EnvironmentalKnowledgeService;
import com.sky.vo.AjaxResult;
import com.sky.vo.DataGridView;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 环保知识
 */
@RestController
@RequestMapping("/garbage/environment")
public class EnvironmentalKnowledgeController {
    @Autowired
    private EnvironmentalKnowledgeService service;

    /**
     * 分页查询
     */
    @GetMapping("/listQuest")
    @ApiOperation("分页查询")
    public AjaxResult selectQuestionBankList(EnvironmentalKnowledePageDto dto){
        DataGridView gridView = this.service.selectList(dto);
        return AjaxResult.success("查询成功", gridView.getData(), gridView.getTotal());
    }

    /**
     * 根据ID查找
     */
    @ApiOperation("根据ID查找")
    @GetMapping(value = "/selectById/{environmentId}")
    public AjaxResult selectQuestionBankById(@PathVariable("environmentId") Integer environmentId){
        return AjaxResult.success(service.selectEnvironmentById(environmentId));
    }

    /**
     * 添加
     */
    @ApiOperation("添加")
    @PostMapping("/addEnvironment")
    public AjaxResult addQuestion(@Validated @RequestBody EnvirinmentalKnowledgeSaveDto dto){
        return AjaxResult.toAjax(service.insert(dto));
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping("/updateEnvironment")
    public AjaxResult updateQuestion(@Validated @RequestBody EnvirinmentalKnowledgeSaveDto dto){
        return AjaxResult.toAjax(this.service.update(dto));
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @DeleteMapping("/deleteEnvironment/{environmentIds}")
    public AjaxResult deleteQuestion(@PathVariable Long[] environmentIds){
        return AjaxResult.toAjax(service.deleteBatch(environmentIds));
    }

}
